-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(markdown): snippet partial import #2225
Conversation
a90b2a2
to
037aa14
Compare
Hi @noelmace, thanks for opening a PR. I discussed with the team and that's definitely something we could add in the next release 👍 I'll do a review ASAP |
Only import a code file region (VS Code `#region <name>` comments, instead of the whole file content) using a new `#region` parameter: `<<< @/path/file.ext#region{1-2}`
permit nesting regions for partial code snippets import
6f58672
to
da909e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bad regexp was introducing a regression, as only one digit was accepted for code highlight. This error permitted to identify that when an invalid path is given, "src" falls down to CWD. This was leading to an ESDIR "invalid operation on a directory" error.
Thx @kefranabg. I fixed this in the last commit and added a new test as requested. |
see the related issue in Vuepress at https://github.com/vuejs/vuepress/pull/2225\#pullrequestreview-383299796
see the related issue in Vuepress at https://github.com/vuejs/vuepress/pull/2225\#pullrequestreview-383299796
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The @ symbol is always relative to the directory where the command is executed. And @alias cannot be used |
see the related issue in Vuepress at https://github.com/vuejs/vuepress/pull/2225\#pullrequestreview-383299796
see the related issue in Vuepress at https://github.com/vuejs/vuepress/pull/2225\#pullrequestreview-383299796
see the related issue in Vuepress at https://github.com/vuejs/vuepress/pull/2225\#pullrequestreview-383299796
Only import a portion of a code file delimited by VS Code custom regions markers, based on the region key you set via a fragment identifier (
#
):/docs/hello-world.md
# Hello World <<< @/src/hello-world.js#function-def{1-2}
/src/hello-world.js:
Motivation
Contents presented with Vuepress (documentation, tutorials, etc.) may (often?) be related to some "real" projects. Ensuring the code snippets in the doc and the "real" code is very important for this use case. Yet, it can be difficult, or even impossible, to split each code sample in a dedicated file. Therefore, some misleading code lines may be shown in the code snippet only because the author needs it in the project.
For example, if I want to show a function in the doc, but I need an
export
in order to use this function in my project, I would have to show it in the code snippet:Solution
This solution add support for:
path#region
)For more details, see the new documentation and tests.
Compatibility
Does not introduce any breaking change: result stay exactly the same if no fragment identifier is set (no region name is set by default).
Yet, the new syntax isn't backward compatible: adding a fragment identifier to the path will lead to a "cannot find path @/path/file.ext#region" with the current version of Vuepress.
If you want to use this feature before this PR is merged, you can use patch-package as follow:
patches/@vuepress+markdown+1.3.1.patch
)postinstall
scriptSummary
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
You have tested in the following browsers: (Providing a detailed version will be better.)
If adding a new feature, the PR's description includes:
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
Other information
This feature is already used on a daily basis for a pretty heavy (but private) project, alongside a related Pandoc filter which provides this feature: pandoc-import-code.